<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>本地存储</title>
</head>
<body>
  <button onclick="setData()">存储数据</button>
  <button onclick="getData()">读取数据</button>
  <button onclick="deleteData()">删除数据</button>
  <button onclick="deleteAllData()">清空数据</button>
  <script>
    /*
      window.localStorage.setItem('key', 'value')
        localstorage不跨域；
        可以持久化存储 并设置过期时间；
      sessionstorage浏览器关闭讲销毁

    */ 
   let Persion = {name:'tom',age:'18'}
    
    setData=()=>{
      // 存储普通键值对
      window.localStorage.setItem('name','jarry')
      window.localStorage.setItem('age','20')
      // 存储对象
      window.localStorage.setItem('persion',JSON.stringify(Persion))
    }
    getData=()=>{
      console.log(window.localStorage.getItem('persion'))
    }
    deleteData=()=>{
      window.localStorage.removeItem('persion')
    }
    deleteAllData=()=>{
      window.localStorage.clear()
    }
  </script>
</body>
</html>